package net.cyl.config;


import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.redisson.api.RedissonClient;

@Configuration
public class RedissionConfiguration {
    @Value("${spring.redis.host}")
    private String redisHost;

    @Value("${spring.redis.port}")
    private String redisPort;


    @Value("${spring.redis.password}")
    private String redisPassword;
@Bean
public RedissonClient redissonClient() {
    Config config = new Config();
    config.useSingleServer()
        .setAddress("redis://" + redisHost + ":" + redisPort)
        .setPassword(redisPassword)
        .setConnectionPoolSize(16)
        .setConnectionMinimumIdleSize(4)
        .setTimeout(10000)
        .setConnectTimeout(10000)
        // 开启 Netty 心跳机制（单位：毫秒）
        .setKeepAlive(true)                // 启用 TCP KeepAlive
        .setTcpNoDelay(true)               // 提升响应速度
        .setPingConnectionInterval(5000)   // 每隔 5 秒发送一次 PING 包保持连接活跃
        .setIdleConnectionTimeout(30000);  // 空闲连接超时时间（毫秒）

    return Redisson.create(config);
}


}
